package com.ecoolex.ying.space.api.graphql;

import java.util.List;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.modularize.api.service.ad.Ad;
import com.ecoolex.framework.modularize.api.service.ad.AdService;
import com.ecoolex.framework.modularize.api.service.storage.StorageInfo;
import com.ecoolex.framework.modularize.api.service.storage.StorageService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import com.ecoolex.ying.space.entity.GoodsCategory;
import com.ecoolex.ying.space.ws.GoodsCategoryService;


@GraphQL2Module(type = GraphQL2Module.Type.User, description = "商品分类查询")
public class GoodsCategoryGraphql {

    @Reference
    private GoodsCategoryService goodsCategoryService;

    @Autowired
    private StorageService storageService;

    @Autowired
    private AdService adService;

    @TypeField(type = GoodsCategory.class, field = "adList", description = "广告列表")
    public List<Ad> adList(@Source GoodsCategory source, @NonNull String position, @NonNull int size) {
        return adService.query(position, source.getCategoryId().toString(), size);
    }

    @TypeField(type = GoodsCategory.class, field = "image", description = "图片")
    public StorageInfo image(@Source GoodsCategory source) {
        return storageService.get(source.getImage());
    }

    @QueryField(field = "goodsCategoryList", description = "商品分类列表")
    public Pagination<GoodsCategory> query(@NonNull Integer parentCategoryId, @NonNull Page page) {

        return goodsCategoryService.queryCategoryForH5(parentCategoryId, page);
    }
}
